package com.zb.controller;

import com.alibaba.fastjson.JSONObject;
import com.zb.entity.ProjectInfo;
import com.zb.service.ProjectInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class ProjectInfoController {
    @Autowired
    private ProjectInfoService projectInfoService;

    @RequestMapping(value = "listProjectInfo",produces = {"application/json;charset=utf-8"})
    @ResponseBody
    public String listProjectInfo(){
        List<ProjectInfo> list = projectInfoService.listProjectInfo();
        return JSONObject.toJSONString(list);
    }

    @RequestMapping(value = "searchProjectInfo",produces = {"application/json;charset=utf-8"})
    @ResponseBody
    public String searchProjectInfo(int status){
        List<ProjectInfo> list = projectInfoService.listProjectInfoByStatus(status);
        return JSONObject.toJSONString(list);
    }

    @RequestMapping("findById")
    public String findById(int id, Model model){
        ProjectInfo project = projectInfoService.getProjectInfoById(id);
        model.addAttribute("p",project);
        return "shenhe.jsp";
    }

    @RequestMapping("shenhe")
    public String shenhe(int status,int id,Model model){
        int flag=projectInfoService.updateProjectInfo(status, id);
        model.addAttribute("flag",flag);
        return "list.jsp";
    }
}
